package com.fc.common.util;

import org.apache.poi.xssf.usermodel.XSSFCell;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtils {
    public static boolean isEmpty(String str) {
        return str == null || str.length() == 0;
    }

    public static boolean isNotEmpty(String str) {
        return !isEmpty(str);
    }


    public static boolean isBlank(String str) {
        int strLen;
        if (str != null && (strLen = str.length()) != 0) {
            for(int i = 0; i < strLen; ++i) {
                if (!Character.isWhitespace(str.charAt(i))) {
                    return false;
                }
            }

            return true;
        } else {
            return true;
        }
    }

    public static boolean isNotBlank(String str) {
        return !isBlank(str);
    }

    /**
     *
     * 判断是否是邮箱
     *
     * @return boolean
     */
    public static boolean isEmail(String email)
    {
        if (email==null||email.equals(""))
        {
            return false;
        }

        String check = "^(\\w+((-\\w+)|(.\\w+))*)+\\w+((-\\w+)|(.\\w+))*@([0-9a-z]+(\\.[a-z]{2,})+)$";
        Pattern regex = Pattern.compile(check);
        Matcher matcher = regex.matcher(email);

        return matcher.matches();
    }


    /**
     *
     * 判断字符串是否是手机号码
     *
     * @param mobile 字符串
     * @return boolean
     */
    public static boolean isMobile(String mobile)
    {
        boolean isMobile = Boolean.FALSE;
        try
        {
            Long.parseLong(mobile);
            isMobile = Boolean.TRUE;
        }
        catch (NumberFormatException nfe)
        {
            isMobile = Boolean.FALSE;
        }

        if (mobile.startsWith("1") && 11 == mobile.length())
        {
            isMobile = Boolean.TRUE;
        }
        else
        {
            isMobile = Boolean.FALSE;
        }

        return isMobile;
    }

    /**
     * 判断单元格是否为空
     *
     * @param cell
     * @return
     */
    public static Boolean checkCellIsBlank(XSSFCell cell) {
        if (cell == null || StringUtils.isBlank(cell.toString())) {
            return true;
        }
        return false;
    }




}
